<?php

namespace app\server;

use \think\facade\Db;
use think\facade\Request;
use think\facade\Cache;
use think\facade\Queue;

class OceanengineServer
{
    public function toCall($id, $clickId,$logId)
    {
        $data = [
            'event_type' => 'active',
            'context' => [
                'ad' => [
                    'callback' => $clickId
                ]
            ],
            'timestamp' => time()
        ];
        $url = 'https://analytics.oceanengine.com/api/v2/conversion';
        $response = curlData($url, json_encode($data), 'POST', '', []);
        $response = json_decode($response, true);
        $status = 2;
        $message = '';
        $code = '-1';
        if (isset($response['code'])) {
            if ($response['code'] == 0) {
                if(!empty($logId)){
                    $ipLogTable = getMonthTable('app_ip_logs');
                    Db::table($ipLogTable)->where(['id'=>$logId])->inc('call_back', 1)->update();
                }
                $status = 1;
            } else {
                $status = 2;
            }
            $message = $response['message'];
            $code = $response['code'];
        }
        $callTable = getMonthTable('app_call');
        edit($callTable, ['id' => $id], ['status' => $status, 'code' => $code, 'message' => $message]);
    }

}


?>